import { asyncRouter, constantRoutes } from '@/router'
const state = {
  router: []
}
const mutations = {
  changeRouter(store, data) {
    store.router = [
      ...constantRoutes,
      ...data
    ]
  }
}
const actions = {
// 在异步请求这里进行筛选
  filterRouter(store, menu) {
    const router = asyncRouter.filter(router => {
      // 筛选动态路由，data中是否与路由名字相同，如果有返回该对象
      return menu.includes(router.name)
    })
    store.commit('changeRouter', router)
    return router
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

